package com.wangzhen.codebase;

public class VolatileDemo2 {

    int x = 0;

    public void writeX(){
        x = 42;
    }

    public void readX(){
        System.out.println(x);
    }

    public static void main(String[] args) throws InterruptedException {
        VolatileDemo2 demo = new VolatileDemo2();
        Thread t1 = new Thread(() -> {
            demo.writeX();
        });
        Thread t2 = new Thread(() -> {
            demo.readX();
        });
        t1.start();t2.start();

        t1.join();
        t2.join();
    }
}
